<script>
  var reachableNodes = function (n, edges, restricted) {
    const obj = {};
    for(let i =0;i<n;i++){
      obj[i] = {};
    }
    edges.forEach(el => {
      el.sort((a, b) => a - b);
      obj[el[0]][el[1]] = obj[el[1]]||{};
    }); 
    console.log(obj)
  };
  console.log(reachableNodes(7, [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], [4,5]))
</script>